package com.itlong.cloud.property;


import com.itlong.cloud.noncore.property.IPropertyOperatingReportServiceClient;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

/**
 * <desc>
 *      物业运营报表统计定时任务
 * </desc>
 *
 * @createDate 2018/08/13
 */
@EnableScheduling // 启用定时任务
@RestController
public class PropertyOperatingReportStatisticsTimedTask {
    private static Logger LOG = LoggerFactory.getLogger(PropertyOperatingReportStatisticsTimedTask.class);

    @Autowired
    IPropertyOperatingReportServiceClient iPropertyOperatingReportServiceClient;

    /**
     * <desc>
     *      定时任务统计每月的账单数据
     * </desc>
     *
     * @throws Exception
     * @author Jiaqi.X
     * @createDate 2018/08/14
     */
    @Scheduled(cron = "0 30 * * * ?") // 每天凌晨执行
//    @Scheduled(cron = "0 0/1 * * * ?") // 每天凌晨执行
    public void statisticsForDay() throws Exception {
        try {
            iPropertyOperatingReportServiceClient.statisticsForMonth();
//            LOG.info("【定时任务】定时统计账单数据成功");
        } catch (Exception e) {
            LOG.error("【定时任务】定时统计账单数据失败");
            throw e;
        }
    }

    /**
     * <desc>
     *      定时任务统计每年的账单数据
     * </desc>
     *
     * @throws Exception
     * @author Jiaqi.X
     * @createDate 2018/08/14
     */
    @Scheduled(cron = "0 50 * * * ?") // 每天凌晨执行
//    @Scheduled(cron = "0 0/1 * * * ?") // 每天凌晨执行
    public void statisticsForMonth() throws Exception {
        try {
            iPropertyOperatingReportServiceClient.statisticsForYear();
//            LOG.info("【定时任务】定时统计每年账单数据成功");
        } catch (Exception e) {
            LOG.error("【定时任务】定时统计每年账单数据失败");
            throw e;
        }
    }

    /**
     * <desc>
     *      定时任务统计数据分析数据
     * </desc>
     *
     * @throws Exception
     * @author Jiaqi.X
     * @createDate 2018/08/14
     */
    @Scheduled(cron = "0 50 * * * ?") // 每天凌晨执行
//    @Scheduled(cron = "0 0/1 * * * ?") // 每天凌晨执行
    public void statisticsAnalyseForMonth() throws Exception {
        try {
            iPropertyOperatingReportServiceClient.statisticsAnalyseForMonth();
//            LOG.info("【定时任务】定时统计数据分析数据成功");
        } catch (Exception e) {
            LOG.error("【定时任务】定时统计数据分析数据失败");
            throw e;
        }
    }
}